package UseIO.UseFileInOutStream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileTryCatch {
    public static void main(String[] args) {

    }

    public static void method01(){
        FileInputStream fInput = null;
        FileOutputStream fOutput = null;
        try{
            fInput = new FileInputStream("/Users/wukai/Movies/01-模块重新导入_recv.mp4");
            fOutput = new FileOutputStream("8.内置模块/UseIO/copyFast.mp4");
            int b;
            byte[] bytes = new byte[1024 * 1024 * 5];
            while ((b=fInput.read(bytes))!= -1){
                fOutput.write(bytes,0,b);
            }

        }catch (IOException e){
            e.printStackTrace();
        }finally {
            // 先开先关
            if(fInput !=null){
                try{
                    fInput.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }

            if(fOutput != null){
                try{
                    fOutput.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }

    }


    public static void method02(){
        try(
                FileInputStream fInput = new FileInputStream("/Users/wukai/Movies/01-模块重新导入_recv.mp4");
                FileOutputStream fOutput = new FileOutputStream("8.内置模块/UseIO/copyFast.mp4");){
            int b;
            byte[] bytes = new byte[1024 * 1024 * 5];
            while ((b=fInput.read(bytes))!= -1){
                fOutput.write(bytes,0,b);
            }

        }catch (IOException e){
            e.printStackTrace();
        }
    }

    public static void method03() throws IOException{
        FileInputStream fInput = new FileInputStream("/Users/wukai/Movies/01-模块重新导入_recv.mp4");
        FileOutputStream fOutput = new FileOutputStream("8.内置模块/UseIO/copyFast.mp4");
        try(fInput;fOutput){
            int b;
            byte[] bytes = new byte[1024 * 1024 * 5];
            while ((b=fInput.read(bytes))!= -1){
                fOutput.write(bytes,0,b);
            }

        }catch (IOException e){
            e.printStackTrace();
        }
    }

}
